#include <gflags/gflags.h>
#include "../../../Common/data_es.hpp"
#include <thread>

DEFINE_bool(log_mod,false,"true为发布模式,false为调试模式");
DEFINE_string(log_file,"","发布模式下日志存储的文件");
DEFINE_int32(log_level,0,"要输出的日志等级");

DEFINE_string(host_list,"http://127.0.0.1:9200/","es服务器的URL");

int main(int argc,char* argv[])
{ 
    google::ParseCommandLineFlags(&argc,&argv,true);
    zzy_mims::init_logger(FLAGS_log_mod,FLAGS_log_file,(spdlog::level::level_enum)FLAGS_log_level);
    auto es_client =zzy_mims::ESClientFactory::create({FLAGS_host_list});
    zzy_mims::ESUser::ptr es_user = std::make_shared<zzy_mims::ESUser>(es_client);
    es_user->CreateIndex();
    es_user->AppendData("user_id1","phone1","姓名1","avatar_id1","description1");//姓名是ik_max_word分析器是中文分词常用的分词器，不能分词英文
    es_user->AppendData("user_id2","phone2","姓名2","avatar_id2","description2");
    std::this_thread::sleep_for(std::chrono::seconds(1));
    auto user_list = es_user->Search("名",{"user_id2"});
    for(auto &u:user_list)
    {
        std::cout << "-----------------" << std::endl;
        std::cout << u.user_id() << std::endl;
        std::cout << u.phone() << std::endl;
        std::cout << u.nickname() << std::endl;
        std::cout << u.description() << std::endl;
        std::cout << u.avatar_id() << std::endl;
    }
    return 0;
}
